<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数也可以访问函数外部定义的变量</title>
</head>

<body>
    <p>函数可以访问定义在函数外的变量：</p>
    <button type="button" onclick="myFunction()">点我</button>
    <p id="demo"></p>
    <script>
        var a = 4;
        function myFunction() {
            document.getElementById("demo").innerHTML = a * a;
        }
    </script>
</body>

</html>